-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Example] Add TADF材料分子的光电性质预测 #974
base: develop
Are you sure you want to change the base?
Conversation
Thanks for your contribution! |
|
请起一个合适的标题 @YfB1125 ,并补充一下PR的简单描述 |
commit代码之前请安装pre-commit,并且使用pre-commit格式化代码,否则code-style-check CI无法通过 |
https://paddlescience-docs.readthedocs.io/zh-cn/latest/zh/development/ 辛苦按照开发指南再整理一下代码规范和文档 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
各文件已上传,如下:
- https://paddle-org.bj.bcebos.com/paddlescience/models/TADF/Est/Est_pretrained.pdparams
- https://paddle-org.bj.bcebos.com/paddlescience/models/TADF/angle/angle_pretrained.pdparams
- https://paddle-org.bj.bcebos.com/paddlescience/models/TADF/f/f_pretrained.pdparams
- https://paddle-org.bj.bcebos.com/paddlescience/datasets/TADF/Est/Est.dat
- https://paddle-org.bj.bcebos.com/paddlescience/datasets/TADF/Est/smis.txt
- https://paddle-org.bj.bcebos.com/paddlescience/datasets/TADF/angle/angle.dat
- https://paddle-org.bj.bcebos.com/paddlescience/datasets/TADF/angle/smis.txt
- https://paddle-org.bj.bcebos.com/paddlescience/datasets/TADF/f/f.dat
- https://paddle-org.bj.bcebos.com/paddlescience/datasets/TADF/f/smis.txt
- https://paddle-org.bj.bcebos.com/paddlescience/docs/TADF/Est/test.png
- https://paddle-org.bj.bcebos.com/paddlescience/docs/TADF/angle/test.png
- https://paddle-org.bj.bcebos.com/paddlescience/docs/TADF/f/test.png
TADF/Est/est_paddle_train.py
Outdated
from sklearn.decomposition import PCA | ||
from sklearn.model_selection import train_test_split | ||
|
||
paddle.device.set_device("cpu") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要指定运行设备为cpu呢
TADF/Est/est_paddle_train.py
Outdated
EPOCHS = 200 | ||
LR = 0.0001 | ||
BATCH = 8 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TADF/Est/est_paddle_train.py
Outdated
BATCH = 8 | ||
|
||
data = [] | ||
for line in open("D://resources//machine learning//paddle//2024-08//Est.dat"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用相对路径,./data/xxx
即可
TADF/Est/est_paddle_train.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个文件和train.py的区别是?
## 4.模型构建 | ||
深度神经网络为含有两层隐藏层的神经网络,第一层隐藏层含有587个神经元,第二层隐藏层含有256个神经元,隐藏层之间加入Dropout。 | ||
|
||
``` | ||
class Net(nn.Layer): | ||
|
||
def __init__(self): | ||
super(Net, self).__init__() | ||
self.fc1 = paddle.nn.Linear(in_features=587, out_features=587) | ||
self.fc2 = paddle.nn.Linear(in_features=587, out_features=256) | ||
self.fc3 = paddle.nn.Linear(in_features=256, out_features=1) | ||
self.dropout = paddle.nn.Dropout(p=0.5) | ||
self.relu = paddle.nn.ReLU() | ||
|
||
def forward(self, _input): | ||
x = self.fc1(_input) | ||
x = self.relu(x) | ||
x = self.dropout(x) | ||
x = self.fc2(x) | ||
x = self.relu(x) | ||
x = self.dropout(x) | ||
x = self.fc3(x) | ||
output = self.relu(x) | ||
return output.squeeze(axis=-1) | ||
def initialize(self): | ||
"""初始化权重""" | ||
for m in self.sublayers(): | ||
if isinstance(m, nn.Linear): | ||
paddle.nn.initializer.XavierNormal()(m.weight) | ||
``` | ||
## 5.模型训练 | ||
|
||
``` | ||
def train(model,X_train,Y_train,X_val,Y_val,batchsize,lr,epochs): | ||
train_loader = paddle.io.DataLoader(Mydataset(X_train,Y_train), batch_size=batchsize, shuffle=True, num_workers=0) | ||
loss_func = paddle.nn.MSELoss() | ||
optimizer = paddle.optimizer.Adam(parameters=model.parameters(),learning_rate=lr,beta1=(0.9, 0.99)[0], | ||
beta2=(0.9, 0.99)[1],weight_decay=1e-5) | ||
train_Loss =[] | ||
val_Loss = [] | ||
for epoch in range(epochs): | ||
model.train() | ||
train_loss = 0. | ||
print(epoch) | ||
for i,data in enumerate(train_loader): | ||
input_,tar = data | ||
output = model(input_) | ||
loss = loss_func(output,tar) | ||
rmse = paddle.sqrt(loss) | ||
optimizer.clear_grad() | ||
rmse.backward() | ||
optimizer.step() | ||
train_loss += loss.item() | ||
train_loss *= batchsize | ||
train_loss /= len(X_train) | ||
train_Loss.append(train_loss) | ||
|
||
with paddle.no_grad(): | ||
val_pre = model(paddle.to_tensor(X_val)) | ||
#val_pre = val_pre*std+mean | ||
val_loss = loss_func(val_pre, paddle.to_tensor(Y_val)) | ||
val_loss = paddle.sqrt(val_loss) | ||
val_loss = val_loss.detach().numpy() | ||
val_Loss.append(val_loss) | ||
|
||
return train_Loss,val_Loss | ||
``` | ||
## 6. 优化器构建 | ||
训练器采用Adam优化器 | ||
``` | ||
optimizer = paddle.optimizer.Adam(parameters=model.parameters(),learning_rate=lr,beta1=(0.9, 0.99)[0], | ||
beta2=(0.9, 0.99)[1],weight_decay=1e-5) | ||
``` | ||
## 7. 模型保存 | ||
``` | ||
paddle.save(model.state_dict(), "D://FILE_YFBU//paddle//model//f.pdparams") | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档内的所有代码块请使用引用格式,引用代码文件的内容,否则要维护两份代码,参考:
PaddleScience/docs/zh/examples/allen_cahn.md
Lines 94 to 100 in 5d710f6
``` py linenums="63" | |
--8<-- | |
examples/allen_cahn/allen_cahn_piratenet.py:63:64 | |
--8<-- | |
``` | |
TADF/angle/angle_paddle_test.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改建议同Est案例
TADF/angle/angle_paddle_train.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改建议同Est案例
TADF/angle/angle_ppsci.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 修改建议同Est案例
- angle_paddle_train和angle_ppsci的区别是什么,是否可以只保留一个文件?
- 文件名请重新命名为具有实际意义的名字,angle_ppsci不太能看出来这个文件是做什么的,可以是train.py或者main.py
TADF/f/f_paddle_train.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改建议同Est和Angle案例
TADF材料分子的光电性质预测
PR types
PR changes
Describe
有机发光二极管(OLED)具有高效率、结构灵活和低成本的优势,在先进显示和照明技术中受到广泛关注。在有机发光二极管器件中,电注入载流子以1:3的比例形成单线态和三线态激子。以纯荧光材料为发光材料构建的OLED发光效率IQE理论极限为25%。另一方面,有机金属复合物发光材料通过引入稀有金属(Ir,Pt等)带来强自旋轨道耦合(SOC),可以将单线态激子通过系间窜越过程转化成三线态激子,从而利用三线态激子发出磷光,其IQE可达100%,但是稀有金属价格昂贵,为推广使用带来了阻碍。热活化延迟荧光材料(TADF)为解决这些问题提供了新思路,并引起了广泛关注。在TADF中,三线态通过逆系间窜越过程(RISC)转化成单重态并发出荧光,从而实现100%的IQE,而RISC过程很大程度上取决于最低单线态(S1)和最低三线态(T1) 之间的能隙(ΔEST)。根据量子力学理论,ΔEST相当于HOMO和LUMO之间的交换积分的两倍。因此TADF分子的常见设计策略是将电子供体(D)和电子受体(A)以明显扭曲的二面角结合以实现HOMO和LUMO在空间上明显的分离。然而,与ΔEST相反,振子强度(f)需要较大的HOMO和LUMO之间的重叠积分,这二者之间的矛盾需要进一步平衡。